(function($){
    function initSetState() {
        $('.but_set_state').on('click', function(){
            var obj = $(this);
            var state = obj.attr('dstate');
            var id = obj.attr('did');
            var url = obj.attr('durl');
            var info = '删除';
            switch(state) {
                case '-1':
                    info = '删除';
                    break;
                case '0':
                    info = '恢复';
                    break;
                case '1':
                    info = '发布';
                    break;
            }
            layer.confirm(
                '确定要【' + info + '】此账号关联吗？',
                {
                    icon: 3,
                    title: '系统提示',
                    btn: ['确 定', '取 消']
                },
                function(index){
                    layer.close(index);
                    layer.load();
                    $.post(
                        url,
                        {id: id, state: state},
                        function(data){
                            if(data.status == 10000) {
                                location.reload(true);
                            } else {
                                layer.closeAll();
                                layer.alert(data.errmsg);
                            }
                        },
                        'json'
                    );
                },
                function(index){
                    layer.close(index);
                }
            );
        });
    }
    function add() {
        var obj = $(this);
        url = obj.attr('durl');
        layer.open({
            type: 2,
            title: '操作员关联用户账号',
            shadeClose: false,
            shade: 0.8,
            maxmin: true, //开启最大化最小化按钮
            area: ['500px', '300px'],
            content: url
        });
    }
    $(function(){
        initSetState();
        $('.but_add_city').on('click', add);
    });
})(jQuery);